package com.ctshk.sapp.finance.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.rpc.finance.dto.bill.BillConfirmDTO;
import com.ctshk.rpc.finance.req.bill.BillConfirmAddReq;
import com.ctshk.rpc.finance.req.bill.BillConfirmIdReq;
import com.ctshk.rpc.finance.req.bill.RollBackReq;
import com.ctshk.rpc.finance.req.supplier.AprovalReq;
import com.ctshk.rpc.finance.service.IFinanceBillConfirmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 财务认款 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-26
 */
@RestController
@Api(value = "财务认款", tags = "财务认款")
@RequestMapping("/finance-bill-confirm")
public class FinanceBillConfirmController extends BaseController {

    @DubboReference
    private IFinanceBillConfirmService billConfirmService;


    @ApiOperation(value = "提交审批", notes = "提交审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "提交财务认款审批", operDesc = "提交财务认款审批")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid BillConfirmAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billConfirmService.add(req);
    }

    @ApiOperation(value = "认款信息", notes = "认款信息（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "财务认款信息", operDesc = "财务认款信息")
    @PostMapping("/detail")
    public Result<BillConfirmDTO> detail(@RequestBody @Valid BillConfirmIdReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billConfirmService.detail(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "审批财务认款", operDesc = "审批财务认款")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid AprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billConfirmService.approval(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "撤回审批", notes = "撤回审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "撤回认款审批", operDesc = "撤回认款审批")
    @PostMapping("/roll-back")
    public Result rollBack(@RequestBody @Valid RollBackReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billConfirmService.rollBack(req);
    }

}
